﻿using System;
using System.Windows.Forms;
using ReAnimation.Helpers.Common;
using ReAnimation.Helpers.WinForms;
using ReAnimation.MVP.Presenters;
using ReAnimation.MVP.ViewInterfaces;

namespace ReAnimation.MVP.Views
{
    public partial class NewMoleculeDialog : BaseFormView, INewMoleculeDialogView
    {
        public NewMoleculeDialog(NewMoleculeDialogPresenter presenter)
        {
            presenter.View = this;
            InitializeComponent();
        }

        public event EventHandler Cancel;
        public event EventHandler<EventArg<string>> Create;

        public void ShowViewDialog()
        {
            ShowDialog();
        }

        private void newMoleculeButton_Click(object sender, EventArgs e)
        {
            Create.Throw(this,new EventArg<string>(moleculeNameTextBox.Text));
        }

        private void moleculeNameTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
                Create.Throw(this,new EventArg<string>(moleculeNameTextBox.Text));
        }

        private void NewMoleculeDialog_FormClosed(object sender, FormClosedEventArgs e)
        {
            Cancel.Throw(this,EventArgs.Empty);
        }
    }
}
